package controller;


import entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
public class MyController {
    @Resource
    Student student;
    @RequestMapping("/hello")
    public String hello(){
        return "hello springboot";
    }


    @RequestMapping("/stu")
    public Student getStudent(){
        return new Student(1001,"张三",20,"男");
    }

    @RequestMapping("/list")
    public List<Student> getList(){
        ArrayList<Student> arrayList=new ArrayList<>();
        arrayList.add(new Student(1001,"张三",20,"男"));
        arrayList.add(new Student(1002,"张三2",21,"女"));
        arrayList.add(new Student(1003,"张三3",22,"男"));
        return arrayList;
    }


    @RequestMapping("/getParam")
    public void getParam(Integer id,String name,Integer age){
        System.out.println(id+","+name+","+age);
    }

    @RequestMapping("/getParam2")
    public void getParam2(@RequestBody Student student){
        System.out.println(student);
    }


    @RequestMapping("/stuInfo")
    public Student stuInfo(){
        return student;
    }


}
